package cn.tedu.live8.filter;

import cn.tedu.live8.pojo.entity.VipUser;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Slf4j
@WebFilter(filterName = "MyFilter",urlPatterns = {"/vip.html"})
public class Myfilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.debug("request:{}",servletRequest);
        log.debug("request:{}",servletResponse);
        log.debug("request:{}",filterChain);
        HttpServletRequest ht = (HttpServletRequest)servletRequest;
        HttpServletResponse hs  = (HttpServletResponse) servletResponse;
        VipUser user = (VipUser) ht.getSession().getAttribute("user");

        if(user==null){
            hs.sendRedirect("/VipLogin3.html");
        }else {
            filterChain.doFilter(servletRequest,servletResponse);
        }


    }

}
